/*
 * @Author: anxia.ack anchenkai@come-future.com
 * @Date: 2025-04-21 10:43:32
 * @LastEditors: anxia.ack anchenkai@come-future.com
 * @LastEditTime: 2025-04-21 17:27:41
 * @FilePath: /free-learning/src/api/chat-message/index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from "@/utils/request";
import type { ChatMessage, ChatMessageDTO } from "./type";
const BASE_CHAT_MESSAGE_URL = "/api/v1/chat";
/**
 * 获取当前用户发送的消息
 * @returns
 */
export const getSendChatMessage = (): Promise<ChatMessage[]> => {
  return request.get(`${BASE_CHAT_MESSAGE_URL}/sendList`);
};

/**
 * 获取当前用户接收的消息
 * @returns
 */
export const getReceiveChatMessage = (): Promise<ChatMessage[]> => {
  return request.get(`${BASE_CHAT_MESSAGE_URL}/receiveList`);
};

/**
 * 发送消息
 * @param chatMessageDTO
 * @returns
 */
export const sendChatMessage = (
  chatMessageDTO: ChatMessageDTO
): Promise<boolean> => {
  return request.post(`${BASE_CHAT_MESSAGE_URL}/send`, chatMessageDTO);
};

/**
 * 查询未读消息数量
 * @returns
 */
export const queryNoReadMessageCount = (): Promise<number> => {
  return request.get(`${BASE_CHAT_MESSAGE_URL}/queryNoReadMessageCount`);
};

/**
 * 阅读消息
 * @param senderId
 * @returns
 */
export const readChatMessage = (senderId: number): Promise<boolean> => {
  return request.post(`${BASE_CHAT_MESSAGE_URL}/read/${senderId}`);
};

export const requestDeleteAllChatMessage = (hisId: number): Promise<boolean> => {
  return request.delete(`${BASE_CHAT_MESSAGE_URL}/delete/${hisId}`);
};
